/**
 * Created with PhpStorm.
 * User: Shinelon
 * Date: 2015/6/17
 * Time: 14:12
 * To change this template use File | Settings | File Templates.
 */
define(function (require, exports, module) {
    var cl = require("ctool");

    cl.add_bro_sign();

    cl.rootCondiFunc({
        "@/*":function(){
            //统计菜单字数的个数
            $(".navmenu>span").each(function(i){
                var me=$(this);
                var num = $(">a",me).text().length;
                me.addClass("tx_" + num);
            });

            //ie下计算子菜单的长度
            cl.bro("ie7") && $(".navmenu>span").one("mouseover",function(e){
                $(".navsub",this).width(function(){
                    return this.scrollWidth - 24;
                });
            });

            //导航鼠标移动到效果
            $(".navmenu>span")
                .hover(
                    function(){
                        subshow.killDelayCall();
                        subshow.delayCall(333,this);
                    },
                    function(){
                        var m = this;
                        subhide.call(this);
                    }
                )
            ;


            function subshow(m){
                var m = this;
                if(cl.bro("ie6,ie7,ie8"))
                    $(".navsub",m).show();
                else
                    $(".navsub",m).stop().fadeTo(210,1);
            }

            function subhide(m){
                var m = this;
                if(cl.bro("ie6,ie7,ie8"))
                    $(".navsub",m).hide();
                else
                    $(".navsub",m).stop().fadeTo(210,0).hide();;
            }



            //bn滑动效果
            !function(msl){
                if(!msl.length) return;
                require.async(["$/cslid","ctooj"],function(Cslid,cj){
                    var csso = cj.getCJObj(".ban");

                    var animates = [];
                    $(".csele",msl).each(function(i){
                        var me=$(this);

                        var anim;

                        if(me.is(".ban_el_1")){
                            !function(){
                                var subc = $(".subCont",me);
                                var tx = $(".tx,a",subc);
                                var dura = 1000;
                                var distance = 100;
                                anim = function(){
                                    subc
                                        .stop()
                                        .fadeTo(0,0)
                                        .css({left:distance})
                                        .animate({left:0,opacity:1},dura)
                                    ;

                                    tx
                                        .stop()
                                        .css({marginLeft:-distance*2})
                                        .animate({marginLeft:0},dura)
                                    ;
                                }
                            }()

                        }

                        animates[i] = anim;
                    });


                    var c = new Cslid({
                        cont:msl,
                        delay:3600,
                        anim_dura:300,
                        fademode:true,
                        size:{w:"auto",h:csso.sld_h},
                        onScrollStart:function(index){
                            var doanimate = animates[index];
                            if(doanimate){
                                doanimate();
                            }
                        }
                    });


                    msl.prevAll("em").click(function(e){
                        if(!$(e).is(".left")){
                            c.next();
                        }else{
                            c.prev();
                        }
                    });
                });
            }($("#main_slid"));




            var month_label = ["","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"];

            //月份转换
            $(".newlist .illu>i:not(.trans)").html(function(i,tx){
                var m = $(this);
                m.addClass("trans");
                var num = parseInt(tx);
                return month_label[num];
            });



            require.async("ctooj",function(){
                $(".maxon").maxonLite();
                $("[strleng]").textLeng();
            });


            //
            require.async("jqplug/sticky",function(){
                $(".lnav").sticky({
                    className:"lnav_wp",
                    bottomSpacing:360,
                    topSpacing:0
                });


                $(".navbar").sticky({
                    className:"navbar_wp",
                    bottomSpacing:360,
                    topSpacing:0,
                    getWidthFrom:"body",
                    responsiveWidth:true
                });

            })
        },

        //产品展现
        "@/._jobs":function(){
            $("#collapse_ul>li").each(function(i){
                var me=$(this);
                var cont_h = me.prop("scrollHeight");
                var coll_h = 40;

                function collapse(){
                    me.stop().animate({height:coll_h});
                    me.addClass("collapse");
                }

                function expand(){
                    me.stop().animate({height:cont_h});
                    me.removeClass("collapse");
                }

                me.find("h3").click(function(){
                    if(me.is(".collapse")){
                        expand();
                    }else{
                        collapse();
                    }
                });

                if(i!=0){
                    collapse();
                }

            });
        },

        "@/.contact":function(){
            var map = new BMap.Map("bdmap");
            var point = new BMap.Point(121.548505,31.282285);
            var marker = new BMap.Marker(point);  // 创建标注
            map.addOverlay(marker);
            marker.setAnimation(BMAP_ANIMATION_DROP); //跳动的动画
            map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
            map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用
            map.centerAndZoom(point, 18);
        },

        "@/._product":function(){
            var ln = $(".lnav");
            ln.find("a").each(function(i){
                var me=$(this);
                if(ln.attr("aid") == me.attr("aid")){
                    me.addClass("cur");
                }
            });;
        }
    });
    return {};
});